package sfa.model;

import sfa.vo.RegisterVo;

public class RegisterDao extends BaseDao {

	public void saveObs(RegisterVo registerVo) {
		StringBuffer query = new StringBuffer()
		.append("insert into DBSPOTAPP.dbo.OPR_OBSTACLE                                  ")
		.append("(obs_no, obs_nm, cpn_dvcd, obs_type, obs_dvcd, obs_grd, obs_rec_time,   ")
		.append("obs_fin_time, obs_prc_time, obs_state, eff_type, eff_usr,               ")
		.append("acc_psn, acc_psn_team, acc_psn_hq, acc_psn_pos, acc_psn_exp, obs_cog_ch,")
		.append("itsm_rct_cnt, tel_rct_cnt)                                              ")
		.append("values")
		.append("(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)            ");
		
		String obs_no = registerVo.getV_obs_no();
		String obs_nm = registerVo.getV_obs_nm();
		String cpn_dvcd = registerVo.getV_cpn_dvcd();
		String obs_type = registerVo.getV_obs_type();
		String obs_dvcd = registerVo.getV_obs_dvcd();
		String obs_grd = registerVo.getV_obs_grd();
		String obs_rec_time = registerVo.getV_obs_rec_time();
		String obs_fin_time = registerVo.getV_obs_fin_time();
		if (obs_fin_time.equals(""))
			obs_fin_time = null;
		String obs_prc_time = registerVo.getV_obs_prc_time();
		String obs_state = registerVo.getV_obs_state();
		String eff_type = registerVo.getV_eff_type();
		String eff_usr = registerVo.getV_eff_usr();
		String acc_psn = registerVo.getV_acc_psn();
		String acc_psn_team = registerVo.getV_acc_psn_team();
		String acc_psn_hq = registerVo.getV_acc_psn_hq();
		String acc_psn_pos = registerVo.getV_acc_psn_pos();
		String acc_psn_exp = registerVo.getV_acc_psn_exp();
		String obs_cog_ch = registerVo.getV_obs_cog_ch();
		String itsm_rct_cnt = registerVo.getV_itsm_rct_cnt();
		String tel_rct_cnt = registerVo.getV_tel_rct_cnt();
		
		
		getJdbcTemplate().update(query.toString(), new Object[] {obs_no, obs_nm, cpn_dvcd, obs_type, obs_dvcd, obs_grd, obs_rec_time, 
			obs_fin_time, obs_prc_time, obs_state, eff_type, eff_usr, acc_psn, acc_psn_team, acc_psn_hq, acc_psn_pos, 
			acc_psn_exp, obs_cog_ch, itsm_rct_cnt, tel_rct_cnt});
	}

	public String getCanSaveObsNo() {
		
		String query = "select MAX(obs_no) from [DBSPOTAPP].[dbo].[OPR_OBSTACLE]";
		
		int seq = getJdbcTemplate().queryForInt(query, new Object[] {} );
		seq++;
		String retSeq = String.valueOf(seq);
				
		return retSeq;
	}
}
